import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class iteye_com {

	public static void main(String[] args) throws Exception {
		Connection conn = Jsoup.connect("http://www.iteye.com/forums");
		conn.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
		conn.header("Accept-Encoding", "gzip, deflate");
		conn.header("Accept-Language", "en-US,en;q=0.5");
		conn.header("Cache-Control", "max-age=0");
		conn.header("Connection", "keep-alive");
		conn.header("Cookie", "_javaeye_cookie_id_=1346140215324572; _javaeye3_session_=BAh7CjoMdXNlcl9pZGkD0cQQOg9zZXNzaW9uX2lkIiVmMTVjODFiODQwZjk0MDNjYzJlYzViOWQxZWQ1MzVkZToQX2NzcmZfdG9rZW4iMStHcHY0ZGhtS3ZLdDk5d3NrS0E4N1YxS01QL2lEV2l0d1hXaGYydnoyNms9IgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsAOgthdXRoZWR7BzoIdWlkIg5tZWlmYW5nemk6DXByb3ZpZGVyIgljc2Ru--10c5da12021cd7355133a6fe8bcd9f4907838b19");
		conn.header("Host", "www.iteye.com");
		conn.header("If-None-Match", "\"5efabcb1c4cd6fc77488ad93e0a35c84\"");
		conn.header("Referer", "http://www.iteye.com/");
		conn.header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0");

		Document doc = conn.get();

		String onclick = doc.select("#show_list").attr("onclick");

		//System.out.println(onclick);

		Pattern pattern = Pattern.compile("encodeURIComponent\\('(.+)'\\)");

		Matcher matcher = pattern.matcher(onclick);
		matcher.find();
		String authenticity_token = matcher.group(1);

		String onlineurl = "http://www.iteye.com/users/online?authenticity_token=" + authenticity_token;

		Connection conn1 = Jsoup.connect(onlineurl);

		conn1.header("Accept", "text/javascript, text/html, application/xml, text/xml, */*");
		conn1.header("Accept-Encoding", "gzip, deflate");
		conn1.header("Accept-Language", "en-US,en;q=0.5");
		conn1.header("Connection", "keep-alive");
		conn1.header("Cookie", "_javaeye_cookie_id_=1346140215324572; _javaeye3_session_=BAh7CjoPc2Vzc2lvbl9pZCIlZjE1YzgxYjg0MGY5NDAzY2MyZWM1YjlkMWVkNTM1ZGUiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA6EF9jc3JmX3Rva2VuIjErR3B2NGRobUt2S3Q5OXdza0tBODdWMUtNUC9pRFdpdHdYV2hmMnZ6MjZrPToMdXNlcl9pZGkD0cQQOgthdXRoZWR7BzoIdWlkIg5tZWlmYW5nemk6DXByb3ZpZGVyIgljc2Ru--31ef541704d614071703a2e5f9505b8458b70070");
		conn1.header("Host", "www.iteye.com");
		conn1.header("If-None-Match", "\"fcbcc65eb2214014140950686d64c903\"");
		conn1.header("Referer", "http://www.iteye.com/forums");
		conn1.header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0");
		conn1.header("X-Prototype-Version", "1.6.1");
		conn1.header("X-Requested-With", "XMLHttpRequest");

		Document doc2 = conn1.get();
		
		Elements els = doc2.select("a");
		for(Element e: els){
			System.out.println(e.text()+"|"+e.attr("href"));
		}

		

	}

}
